package mqtts

import (
	"fmt"
	mqtt "github.com/eclipse/paho.mqtt.golang"
	"time"
)

/*
  @Description: 向某个mqtt的主题发送信息
  @param client
*/
func Publish(client mqtt.Client) {

	text := "张建宏"
	token := client.Publish("topic/test", 0, false, text)
	token.Wait()
	time.Sleep(time.Second)

}

/*
  @Description: 订阅某个函数的主题
  @param client
*/
func Sub(client mqtt.Client) {

	topic := "topic/zjh"
	token := client.Subscribe(topic, 1, nil)
	token.Wait()
	fmt.Printf("Subscribed to topic: %s", topic)
}
func Sub2(client mqtt.Client) {

	topic := "topic/zjh1"
	token := client.Subscribe(topic, 1, nil)
	token.Wait()
	fmt.Printf("Subscribed to topic: %s", topic)
}

